/***************************************************************************
 *   mgpi_evt_test.c - MGPI Events Handling & Timers System Test           *
 *   Created on 22 październik 2009, 10:22                                 *
 *   Copyright (C) 2009 by cmaster.matso (Maciej Kadłubowski)              *
 *   cmaster.matso@gmail.com                                               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include <MGPI/mgpi.h>

/* STATIC Global Variables */
static MGPI_Container *container;
static MGPI_Filter *filtered_events;
static MGPI_Event *user_event;

/* STATIC Routines Declarations */
static MGPI_BOOL key_proc(MGPI_Component *, SDL_Event *);
static MGPI_BOOL mouse_motion_proc(MGPI_Component *, SDL_Event *);
static MGPI_BOOL mouse_button_proc(MGPI_Component *, SDL_Event *);
static MGPI_BOOL _empty(MGPI_Component *, SDL_Event *);
static MGPI_BOOL user_event_proc(void *, SDL_Event *);

/**
 * Initializes the container (for logic processing purposes).
 */
static void init_container(void) {
    container = (MGPI_Container *) calloc(1, sizeof (MGPI_Container));
    MGPI_CollectGarbage(container);

    container->component.onEvent[MGPI_MOUSE_BUTTON_DOWN] = mouse_button_proc;
    container->component.onEvent[MGPI_MOUSE_BUTTON_UP] = _empty;
    container->component.onEvent[MGPI_MOUSE_MOTION] = mouse_motion_proc;
    container->component.onEvent[MGPI_KEY_DOWN] = key_proc;
    container->component.onEvent[MGPI_KEY_UP] = _empty;
    container->env = MGPI_ENVIRONMENT_3D;

    user_event = (MGPI_Event *)calloc(1, sizeof(MGPI_Event));
    MGPI_CollectGarbage(user_event);

    container->component.onUserEvent =
            (MGPI_BOOL (**)(void *, SDL_Event *))calloc(1, sizeof(MGPI_BOOL (*)(void *, SDL_Event *)));
    MGPI_CollectGarbage(container->component.onUserEvent);

    container->component.onUserEvent[0] = user_event_proc;

    /* TODO: ... */

    return;
}

/**
 * Program entry point.
 */
int main(int argc, char *argv[]) {

    /* TODO: the test... */

    return EXIT_SUCCESS;
}
